<?php
declare (strict_types = 1);

namespace app\api\controller;

use app\lib\Arr;
use app\lib\Show;
use think\Exception;
use think\facade\Log;
use think\response\Json;

class Category extends Base {

    public function index() : Json {
        $result = [];
        try{
            $result = (new \app\business\Category())->list(0, "id, pid, name, url_key");
        }catch (Exception $e){
            Log::error($e->getMessage());
            return show(config("status.success"), "获取数据失败");
        }
        $categories = Arr::getTree($result);
        $categories = Arr::sliceTreeArr($categories);
        return show(config("status.success"), "ok", $categories);
    }

    public function search($id = 0) {
        return show(config("status.success"), "ok", []);
    }
}